//
//  UIApplicationExtensions.swift
//  Fangxukanghan
//
//  Created by 常超群的MacBookPro on 2021/7/16.
//

import UIKit

public extension UIApplication {
    /// 获取当前window
    var ccq_currentWindow: UIWindow? {
        if #available(iOS 13.0, *) {
            if let window = connectedScenes
                .filter({$0.activationState == .foregroundActive})
                .map({$0 as? UIWindowScene})
                .compactMap({$0})
                .first?.windows
                .filter({$0.isKeyWindow}).first {
                return window
            } else if let window = UIApplication.shared.delegate?.window {
                return window
            } else {
                return nil
            }
        } else {
            if let window = UIApplication.shared.delegate?.window {
                return window
            } else {
                return nil
            }
        }
    }
}
